package cz.muni.fi.pb138.videoweb2013.servlets;

import cz.muni.fi.pb138.videoweb2013.backend.ODFTransformation;
import cz.muni.fi.pb138.videoweb2013.backend.ODFTransformationImpl;
import javax.servlet.http.HttpServletResponse;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.action.UrlBinding;

/**
 * export to ods format action
 *
 * @author Filip
 */
@UrlBinding("/action/export")
public class ExportActionBean implements ActionBean{
    private ActionBeanContext context;

    @Override
    public ActionBeanContext getContext() {
        return context;
    }

    @Override
    public void setContext(ActionBeanContext context) {
        this.context = context;
    }
 
    /**
     * exports all mediums from database into ods format
     * 
     * @return file with name videoweb.ods
     */
    @DefaultHandler
    public Resolution exportODF() {
        return new StreamingResolution("text/xml") {
            public void stream(HttpServletResponse response) throws Exception {
                ODFTransformation odf = new ODFTransformationImpl();
                odf.exportAll(response.getOutputStream());
            }
        }.setFilename("videoweb.ods");
    }
}
